// 
// Author: damphat@gmail.com
//

#pragma once
#include "vn/BasicTypes.h"

//////////////////////////////////////////////////////////////////////////
/// class TimeSpan - hold a duration of time

class TimeSpan {
public:
	enum TimeUnit {
		Days,
		Hours,
		Minutes,
		Seconds,
		Miliseconds
	};

public:
	
	// Constructor:

	TimeSpan(Int64 miliseconds = 0);												///
	TimeSpan(int hours, int minutes, int seconds);									///
	TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds = 0);	///
	TimeSpan(double totalLength, TimeUnit unit);									///

	// Properties:

	int GetDays() const;			/// Day part of the timespan
	int GetHours() const;			/// Hour part of the timespan
	int GetMinutes() const;			/// Minute part of the timespan
	int GetSeconds() const;			/// Second part of the timespan
	int GetMilliseconds() const;	/// Millisecond part of the timespan

	// Get total time represent in several unit:

	double GetTotalDays() const;			/// Total time (in days)
	double GetTotalHours() const;			/// Total time (in hours)
	double GetTotalMinutes() const;			/// Total time (in minutes)
	double GetTotalSeconds() const;			/// Total time (in seconds)
	double GetTotalMilliseconds() const;	/// Total time (in milliseconds)

public:
	Int64 data;						/// total miliseconds
};


//////////////////////////////////////////////////////////////////////////
// Operators - time duration calculation

/// unary '-' operator
TimeSpan	operator - (TimeSpan t);

/// binary '+' '-' operator
TimeSpan	operator - (TimeSpan t1, TimeSpan t2);
TimeSpan	operator + (TimeSpan t1, TimeSpan t2);

/// '*' with a double
static TimeSpan	operator * (TimeSpan t, double k) {
	return Int64(t.data * k);
}

/// '/' with a double
static TimeSpan	operator / (TimeSpan t, double k) {
	return Int64(t.data / k);
}

/// '*' with a double
static TimeSpan	operator * (double k, TimeSpan t) {
	return Int64(k * t.data);
}

/// '/' with a double
static TimeSpan	operator / (double k, TimeSpan t) {
	return Int64(k / t.data);
}

// Comparators:

bool		operator ==(TimeSpan t1, TimeSpan t2);	///
bool		operator !=(TimeSpan t1, TimeSpan t2);	///
bool		operator < (TimeSpan t1, TimeSpan t2);	///
bool		operator <=(TimeSpan t1, TimeSpan t2);	///
bool		operator > (TimeSpan t1, TimeSpan t2);	///
bool		operator >=(TimeSpan t1, TimeSpan t2);	///
